Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
ThreeJS: Water2 example throwing "sphere is undefined," error

I'm trying to get the basic ThreeJS Water2 example setup that you can find here: https://threejs.org/examples/?q=water#webgl_water

Source code here: https://github.com/mrdoob/three.js/blob/master/examples/webgl_water.html

The process seems so straightforward it hurts that it's not working: Supply the geometry of a plane to the constructor, supply parameters, and then add that object to the scene. You can see an example of this on line 86 of the examples' source above.

Here's my attempt at doing it inside an Aframe component:

init() {
    let mesh;
    let waterObj;

    this.el.object3D.traverse(obj => {
      if (obj.type == "Mesh") {
        mesh = obj;
      }
    });

    waterObj = new Water(mesh, {
      scale: 4,
      flowDirection: new THREE.Vector2(1, 1),
      textureWidth: 1024,
      textureHeight: 1024
    });

    this.el.object3D.attach(waterObj);
  }
});

but it doesn't seem to work. If I use object3D.attach() it produces an error that says sphere is undefined (no idea what "sphere," is), and if I use object3D = waterObj then the color of the plane slightly changes, but nothing else.

Does anyone have experience with getting this setup?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It should be working as long as you provide the geometry in the constructor, not the mesh:

waterObj = new Water(mesh.geometry, {
  scale: 4,
  flowDirection: new THREE.Vector2(1, 1),
  textureWidth: 1024,
  textureHeight: 1024
});

Also keep in mind that attach won't apply the parent transform to the waterObj, so the plane might appear at (0,0,0).

Other than that - it should be working - check out this a-frame + THREE.Water example

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!